import request from '@/utils/request.js'

export const sendCode = mobile => {
  return request({
    url: '/v1_0/sms/codes/' + mobile
    // url: '/app/v1_0/sms/codes/' + mobile
  })
}

export const login = data => {
  return request({
    // url: '/app/v1_0/authorizations',
    url: '/v1_0/authorizations',
    method: 'POST',
    data
  })
}

// 获取用户个人信息
export const getUserInfo = () => {
  return request({
    // url: '/app/v1_0/user'
    url: '/v1_0/user'
  })
}

// 获取用户频道列表
export const getUserChannels = () => {
  return request({
    // url: '/app/v1_0/user/channels'
    url: '/v1_0/user/channels'
  })
}

// 关注
export const addFollowUser = target => {
  return request({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target
    }
  })
}

// 取消关注
export const removeFollowUser = target => {
  return request({
    url: '/v1_0/user/followings/' + target,
    method: 'DELETE'
  })
}

// 点赞
export const addLikeUser = target => {
  return request({
    url: '/v1_0/article/likings',
    method: 'POST',
    data: {
      target
    }
  })
}

// 取消点赞
export const removeLikeUser = target => {
  return request({
    url: '/v1_0/article/likings/' + target,
    method: 'DELETE'
  })
}

/**
 * 获取用户信息
 * @returns promise
 */
export const getUserProfile = () => {
  return request({
    url: '/v1_0/user/profile',
    method: 'GET'
  })
}

/**
 * 更新用户信息
 * @returns promise
 */
export const updateUserProfile = data => {
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data
  })
}

/**
 * 更新用户头像
 * @returns promise
 */
export const updateUserAvatar = data => {
  return request({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data
  })
}
